<template>
    <div class="product">
        <div class="banner"/>
        <div class="buttonList" >
            <div class="flex" v-for="(item,index) in items" @click="onGeneralClick(item.link||'/',item.queryParams|| null)">
                <div class="button">{{item.name}}</div>
            </div>
            <div class="flex">
                <div class="button" @click="onDeleteDevice()">删除设备</div>
            </div>
        </div>
    </div>
</template>

<script>
    import { Dialog,Toast,Loading,Popup } from 'vant';
    import { post } from "../../js/utils";

    export default {
        name: 'ProductNoGateway',
        components: {},
        data () {
            return {
                devId : this.$route.query.Id,
                items: [{
                    name: "远程分享密码",
                    link: '/remoteSharePassword'
                }, {
                    name: "关联网关",
                    link: '/contactGateway',
                    queryParams: {"devId":this.$route.query.Id}
                }, {
                    name: "保修卡",
                    link: '/guaranteeCard',
                    queryParams: {"devId":this.$route.query.Id}
                }],
            }
        },
        created () {
        },
        methods: {
            onDeleteDevice: function () {
                Dialog.confirm({
                    title: '删除本设备',
                    message: '删除后将重置该设备的相关信息'
                }).then(() => {
                    let _this = this;
                    post("/user/deleteDevice", {
                        devId: _this.devId,
                    }).then(
                        res=>{
                            Toast.success('删除设备成功');
                            this.onGeneralClick('/home',null)
                        }
                    ).catch((err) => {
                        Toast.fail(err);
                    })
                })
            },
            onGeneralClick: function (link, queryParams) {
                this.$router.push({
                    path: link,
                    query: queryParams
                });//其中login是你定义的一个路由模块
            }
        }
    }
</script>

<style scoped>
    .product > .banner {
        width: 100vw;
        height: 30vh;
        background: url(../../assets/product_A3.png) no-repeat center top;
        background-size: 100% 100%;
    }

    .product > .buttonList {
        width: 100vw;
        height: 70vh;
        display: flex;
        flex-direction: column; /*Flex主轴方向为从上到下，交叉轴从左到右*/
        justify-content: center;
    }

    .product > .buttonList > .flex {
        min-height: 8vh;
        margin-top: 8px;
        display: flex;
        justify-content: center;
        line-height: 8vh;
    }

    .product > .buttonList > .flex > .button {
        width: 80vw;
        min-height: 8vh;
        background: url(../../assets/product_orange.png) no-repeat;
        color: #fff;
        background-size: 100% 100%;
        align-self: center;
    }

    .product > .buttonList > .flex > .button:active {
        width: 80vw;
        min-height: 8vh;
        background: url(../../assets/product_grep.png) no-repeat;
        color: orange;
        background-size: 100% 100%;
        align-self: center;
    }


</style>
